/* eslint valid-jsdoc: "off" */

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = (appInfo) => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = (exports = {})

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1733203711661_7539'

  // 配置中间接
  config.middleware = ['errorHandler']

  const userConfig = {
    // myAppName: 'egg',
  }

  config.security = {
    // 关闭 csrf
    csrf: {
      enable: false // 开启csrf
    },
    // 跨域白名单
    domainWhiteList: ['*']
  }
  // 允许跨域的方法
  config.cors = {
    origin: '*',
    allowMethods: 'GET, PUT, POST, DELETE, PATCH'
  }
  // 参数校验
  config.valparams = {
    locale: 'zh-cn',
    throwError: true
  }
  // 文件上传
  config.multipart = {
    mode: 'file'
  }
  // oss存储 腾讯云
  config.cos = {
    secretId: 'AKIDUwVxKaikjbR9rUIHCPqKnJmGqTFC7EJJ', // 替换为你的SecretId
    secretKey: 'IgDxeXmCseNHGFRn6WQDvW0LnPG0YuW6', // 替换为你的SecretKey
    Bucket: 'echo-1314434456',
    region: 'ap-chengdu' // 例如：ap-shanghai
  }
  // 数据库配置
  config.sequelize = {
    dialect: 'mysql',
    host: '127.0.0.1',
    username: 'echo',
    password: '123456',
    port: 3306,
    database: 'echo',
    // 中国时区
    timezone: '+08:00',
    define: {
      // 取消数据表名复数
      freezeTableName: true,
      // 自动写入时间戳 created_at updated_at
      timestamps: true,
      // 字段生成软删除时间戳 deleted_at
      // paranoid: true,
      createdAt: 'created_at',
      updatedAt: 'updated_at',
      // deletedAt: 'deleted_at',
      // 所有驼峰命名格式化
      underscored: true
    }
  }

  return {
    ...config,
    ...userConfig
  }
}
